
//
//  ShoppingCell.m
//  瀑布流
//
//  Created by mac on 2017/3/16.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "ShoppingCell.h"
#import "WaterFallView.h"
#import "ShoppingModel.h"


@interface ShoppingCell()

@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UILabel *priceLabel;

@end


@implementation ShoppingCell

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        UIImageView *imageView = [[UIImageView alloc] init];
        self.imageView = imageView;
        [self addSubview:imageView];
        
        UILabel *priceLabel = [[UILabel alloc] init];
        //设置背景透明度
        priceLabel.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
        priceLabel.textAlignment = NSTextAlignmentCenter;
        priceLabel.textColor = [UIColor whiteColor];
        self.priceLabel = priceLabel;
        [self addSubview:priceLabel];
        
    }
    return self;
}



+ (instancetype)cellWithWaterFallView:(WaterFallView *)waterFallView{
    static NSString *ID = @"SHOP";
    ShoppingCell *cell = [waterFallView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[ShoppingCell alloc] init];
        cell.identifier = ID;
        
    }
    return cell;
}

//
- (void)setShop:(ShoppingModel *)shop{
    _shop = shop;

    self.priceLabel.text = shop.price;
    
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:shop.img] placeholderImage:[UIImage imageNamed:@"loading"]];
}


- (void)layoutSubviews{
    [super layoutSubviews];
    
    self.imageView.frame = self.bounds;
    
    CGFloat priceW = self.bounds.size.width;
    CGFloat priceH = 25;
    CGFloat priceX = 0;
    CGFloat priceY = self.bounds.size.height - priceH;
    self.priceLabel.frame = CGRectMake(priceX, priceY, priceW, priceH);
    
}


@end
